#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libflv.h>

#define OPTION(flag, str)						\
	if(strcmp(__argv[i], (flag)) == 0 && (i+1) < __argc)		\
	{								\
		(str) = __argv[++i];					\
		continue;						\
	}

void createMp3Stream(const char *infile, const char *outfile)
{
	Stream *mp3;
	FlvStream *flv;
	int len, tp;
	
	mp3 = Mp3Audio_newStream(infile, 0);
	flv = FlvStream_newStream(outfile, mp3, NULL, FLV_VERSION_1);
	len = 200; // 200 ms
	tp = 0;
	
	while(len > 0)
	{
		len = 200;
		len = FlvStream_writeAudioTag(flv, tp, len, NULL);
//		printf("tp %i, len %i\n", tp, len);
		tp += len;
	}
}

int main() 
{
	
	int i=0;
	const char *infile = NULL;
	const char *stream = NULL;
		
	for(i = 1; i < __argc; i++)
	{
		OPTION("-i", infile);
		OPTION("-o", stream);
	}
	
	if(infile == NULL || stream == NULL)
	{
		exit(-1);
	}
	
	createMp3Stream(infile, stream);
	
	return 0;
}
